x <- read.dta("iggy.dta")
## cut Ignatieff supporters (n=576)
x <- x[x$candidate_last_name != "Ignatieff", ]
## define treatments
x$mailingsCount <- x[, 26]
x$isMailed <- as.integer(x$mailingsCount > 0)
## create young, senior, female
x$young <- 0
x$young[x$represents %in% c("YF", "YM")] <- 1
x$senior <- 0
x$senior[x$represents %in% c("SF", "SM")] <- 1
x$female <- 0
x$female[x$represents %in% c("AF", "YF", "SF", "WC")] <- 1
## fix pledged candidate labels:
x$candidate_last_name[x$candidate_last_name == "2ison"] <- "Brison"
x$candidate_last_name[x$candidate_last_name == "Hall Findlay"] <- "HallFindlay"
x$candidate_last_name[x$candidate_last_name == "Undeclared / Non-d\xe9clar\xe9"] <- "Undeclared"
## dummify covariates
x <- cbind(x, dummify(as.factor(x$province)))
x <- cbind(x, dummify(as.factor(x$candidate_last_name)))
## cut nonrespondents (n=161)
x.resp <- x[!is.na(x[,30]),]

### outcome mapping:
# 1=Ignatieff
# 2=Rae
# 3=Kennedy
# 4=Dion
# 5=Dryden
# 6=Volpe
# 7=Bryson
# 8=Hall Findlay
## Ignatieff ranking.  1=first, 2=sec, 3=third, 4=notranked, 5=never
x.resp$IgRank <- 4
x.resp$IgRank[which(x.resp$first == 1)] <- 1
x.resp$IgRank[which(x.resp$second == 1)] <- 2
x.resp$IgRank[which(x.resp$third == 1)] <- 3
for(i in 34:39){  ##names(x)[34:39] [1] "never1" "never2" "never3" "never4" "never5" "never6"
  x.resp$IgRank[which(x.resp[, i] == 1)] <- 5 
}
rm(i)
